package com.pinyoumei.app.activity.ShoppingCenter;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.pinyoumei.app.R;
import com.pinyoumei.app.activity.BaseActivity;
import com.pinyoumei.app.utils.OnResponseListener;
import com.pinyoumei.app.utils.ToastUtils;
import com.pinyoumei.app.utils.WXShare;


/**
 * Created by Administrator on 2020-12-25.
 * --------- 日期 ------- 维护人 ------------ 变更内容 --------
 * 2020-12-25        Administrator             新增Person类
 * 2020-12-25        Administrator             增加sex属性
 * 商品分享
 */
public class ShopShareActivity extends BaseActivity implements View.OnClickListener {




    private TextView tvShare;
    private TextView tvTitle;
    private WXShare wxShare;
    private String share_price = "";
    private String share_content = "";
    private String share_url = "";
    private String tb = "";
    private TextView tv_copy;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_shop_share);

        tb = getIntent().getStringExtra("coupon_command");
        share_price = getIntent().getStringExtra("share_price");
        share_content = getIntent().getStringExtra("share_content");
        share_url = getIntent().getStringExtra("share_url");

        InitWidget();
        InitData();
    }



    private void InitWidget() {
        wxShare = new WXShare(this);
        wxShare.setListener(new OnResponseListener(){
            @Override
            public void onSuccess(){
                //分享成功
                ToastUtils.showShort("分享成功");
            }
            @Override
            public void onCancel(){
                //分享取消
                ToastUtils.showShort("分享取消");
            }
            @Override
            public void onFail(String message){
                //分享失败
                ToastUtils.showShort("分享失败");
            }
        });

        RelativeLayout relativeFinish = findViewById(R.id.relative_finish);
        relativeFinish.setOnClickListener(this);
        tvShare = findViewById(R.id.tv_share);
        tvTitle = findViewById(R.id.tv_title);
        tv_copy = findViewById(R.id.tv_copy);
        tv_copy.setOnClickListener(this);
        LinearLayout  linearLayoutWeixinhaoyou = findViewById(R.id.linearLayout_weixinhaoyou);
        linearLayoutWeixinhaoyou.setOnClickListener(this);
        LinearLayout  linearLayoutPengyouquan = findViewById(R.id.linearLayout_pengyouquan);
        linearLayoutPengyouquan.setOnClickListener(this);
        LinearLayout  linearLayoutCopy = findViewById(R.id.linearLayout_copy);
        linearLayoutCopy.setOnClickListener(this);
    }


    private void InitData() {
        tvShare.setText("分享赚" +share_price + "，分享后不要忘记粘贴分享文案！");
        tvTitle.setText(share_content);

        if (!TextUtils.isEmpty(tb)){
            tv_copy.setText("复制吱口令");
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
        	case R.id.relative_finish:
        		finish();
        		break;
            case R.id.linearLayout_weixinhaoyou://点击分享微信好友(0:好友 1：朋友圈)
                if (!TextUtils.isEmpty(share_url)){
                    wxShare.shareUrl(0, ShopShareActivity.this,share_url,"",share_content);

                }

                break;
            case R.id.linearLayout_pengyouquan://点击分享朋友圈
                if (!TextUtils.isEmpty(share_url)){
                    wxShare.shareUrl(1, ShopShareActivity.this,share_url,"",share_content);

                }
                break;


            case R.id.tv_copy:
                //复制uri地址
                if (!TextUtils.isEmpty(tb)){
                    if (!TextUtils.isEmpty(share_content)){
                        //复制
                        try {
                            //获取剪贴板管理器
                            ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
                            // 创建普通字符型ClipData
                            ClipData mClipData = ClipData.newPlainText("Label", tb);
                            // 将ClipData内容放到系统剪贴板里。
                            cm.setPrimaryClip(mClipData);
                            ToastUtils.showShort("口令复制成功");
                            return ;
                        } catch (Exception e) {
                            return ;
                        }
                    }
                }else{
                    if (!TextUtils.isEmpty(share_url)){
                        //复制
                        try {
                            //获取剪贴板管理器
                            ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
                            // 创建普通字符型ClipData
                            ClipData mClipData = ClipData.newPlainText("Label", share_url);
                            // 将ClipData内容放到系统剪贴板里。
                            cm.setPrimaryClip(mClipData);
                            ToastUtils.showShort("地址复制成功");
                            return ;
                        } catch (Exception e) {
                            return ;
                        }
                    }
                }

                break;
                case R.id.linearLayout_copy:
                //复制文本
                    if (!TextUtils.isEmpty(share_content)){
                        //复制
                        try {
                            //获取剪贴板管理器
                            ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
                            // 创建普通字符型ClipData
                            ClipData mClipData = ClipData.newPlainText("Label", share_content);
                            // 将ClipData内容放到系统剪贴板里。
                            cm.setPrimaryClip(mClipData);
                            ToastUtils.showShort("文本复制成功");
                            return ;
                        } catch (Exception e) {
                            return ;
                        }
                    }
                break;

            default:
        		break;
        }
    }
}
